package com.zxy.config.config;

import com.zxy.config.handler.AuthorizationHandler;
import com.zxy.config.handler.WebUrlHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private WebUrlHandler webUrlHandler;

    @Autowired
    private AuthorizationHandler authorizationHandler;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // url拦截器需要去拦截所有的url请求，来做一次判断当前请求到的url是否开启了允许访问
        registry.addInterceptor(webUrlHandler).addPathPatterns("/**");
        registry.addInterceptor(authorizationHandler).excludePathPatterns("/user/login").addPathPatterns("/**");
    }
}
